package com.qf.handle;



import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author 刘亚康
 * @Date 2020/3/26
 * @Version 1.0'
 * @Description 配置mybatis的自动填充
 */
@Slf4j
@Component
public class MyHandle implements MetaObjectHandler {
    /**
     * 在插入时填充
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("insert start");
        //三个参数：字段名，字段值，要给哪个字段处理
        this.setFieldValByName("createUser","1",metaObject);
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);
        this.setFieldValByName("orderTime",new Date(),metaObject);
        this.setFieldValByName("updateUser","1",metaObject);
        this.setFieldValByName("uDelete",0,metaObject);
        this.setFieldValByName("orderIsDelete",0,metaObject);
        this.setFieldValByName("goodsState",0,metaObject);
        this.setFieldValByName("addressIsDelete",0,metaObject);
        this.setFieldValByName("isDefault",1,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("update start");
        this.setFieldValByName("updateTime",new Date(),metaObject);
        this.setFieldValByName("updateUser","1",metaObject);
    }
}